var imageUtil = require('../../utils/util.js');
var app = getApp();

 /*var swiper = require("../../static/js/swiper.js");*/



Page({
  /**
   * 页面的初始数据
   */
  data: {
    inputShowed: false,
    inputVal: "",
    httphost: app.data.httphost,
    httpserver: app.data.httpserver,
    showModalStatus: false,
    nullTip:true,
    hiddenmodalput:true,
    card_num:"",
    card_pwd:"",
    
    card_score_num:""
  },
  //取消按钮
cancel: function(){
    this.setData({
        hiddenmodalput: true
    });
},
test_userlogin:function (){
   // 调用API从本地缓存中获取数据
   var session_id = wx.getStorageSync('session_id');
   var header = wx.getStorageSync('header');
   if (session_id == '') {
     wx.showToast({
       title: '您还未登录，请点击我的进行登录！',
       icon: 'none',
       duration: 2000
     })
     return;
   }
},
//确认
confirm: function(e){
  var that = this;
  var card_num = that.data.card_num;
  var card_pwd = that.data.card_pwd;
  var card_score_num = that.data.card_score_num;
  console.log("充值")
  // 调用API从本地缓存中获取数据
  var session_id = wx.getStorageSync('session_id');
  var header = wx.getStorageSync('header');
  if (session_id == '') {
    wx.showToast({
      title: '您还未登录，请点击我的进行登录',
      icon: 'none',
      duration: 2000
    })
    return;
  }
  wx.request({
    url: app.data.httpserver + 'userScore/userCard',
    header: wx.getStorageSync('header'),
    data:{
      card_num:card_num,card_pwd:card_pwd,card_score_num:card_score_num
    },
    success:function(resqust){
      if(resqust.data.flag==0){
        that.showTip("卡号或者密码错误！")
      }else if(resqust.data.flag==1){
        that.showTip("此卡已被冻结，请联系客服！")
      }else if(resqust.data.flag==2){
        that.showTip("充值数量大于卡片余额！")
      }else{
        that.setData({
          hiddenmodalput: true
        })
        wx.navigateTo({
          url: '../score/index'
        })
      }
    }
  })
  
},
card_num: function(e) {
  this.setData({
    card_num: e.detail.value
  })
},
card_pwd: function(e) {
  this.setData({
    card_pwd: e.detail.value
  })
},
card_score_num: function(e) {
  this.setData({
    card_score_num: e.detail.value
  })
},
  showTip: function(tipTxt) {
    var that = this
    that.setData({
      nullTip : false, //弹窗显示
      tipTxt: tipTxt
    })
    setTimeout(function () {
      that.setData({
        nullTip : true, 
        tipTxt: tipTxt
      }) //1.5秒之后弹窗隐藏
    }, 1500)
  },
  
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function () {

    var that = this; 
    that.setData({
      hiddenmodalput:false
    })
    wx.request({
      url: app.data.httpserver + 'index',
      header: wx.getStorageSync('header'),
      success:function(resqust){
        var banner = resqust.data.bannerlist
        var navigation= resqust.data.navigationlist
        //组合轮播图片
        for (var i = 0; i < banner.length;i++){
          var app_url = banner[i].app_url
          var attr_value = '';
          if (typeof (app_url) != 'undefined' && app_url.indexOf('/')!=-1){
              banner[i].app_url = app_url.split('/')[0];
              // var attr_name_value = app_url.split('?')[1].split('=');
              var attr_value = app_url.split('/')[1];
          }
          banner[i].attr_value = attr_value;
        }
        //组合导航分类
        for (var i = 0; i < navigation.length; i++) {
          var navigation_app_url = navigation[i].navigation_app_url
          var navigation_attr_value = '';
          if (typeof (navigation_app_url) != 'undefined' && navigation_app_url.indexOf('/') != -1) {
            navigation[i].navigation_app_url = navigation_app_url.split('/')[0];
            // var attr_name_value = navigation_app_url.split('?')[1].split('=');
            navigation_attr_value = navigation_app_url.split('/')[1];
          }
          navigation[i].navigation_attr_value = navigation_attr_value;
        }
        that.setData({
          banner: banner,
          navigation: navigation,
          news: resqust.data.newslist,
          tuijian: resqust.data.tuijianlist,
          goods: resqust.data.goodslist,
          cart_count: resqust.data.cart_count,
        })
      }
    })
  },
  bannerLoad: function (e) {
    var imageSize = imageUtil.imageUtil(e)
    this.setData({
      bannerwidth: imageSize.imageWidth,
      bannerheight: imageSize.imageHeight
    })
  }, 
  imageLoad: function (e) {
    var imageSize = imageUtil.imageUtil(e)
    this.setData({
      imagewidth: imageSize.imageWidth,
      imageheight: imageSize.imageHeight
    })
  }, 
  showInput: function () {
    console.log('showInput');
    this.setData({
      inputShowed: true
    });
  },
  hideInput: function () {
    this.setData({
      inputVal: "",
      inputShowed: false
    });
  },
  clearInput: function () {
    this.setData({
      inputVal: ""
    });
  },
  inputTyping: function (e) {
    this.setData({
      inputVal: e.detail.value
    });
  },

  news_list: function () {
    wx.navigateTo({
      url: '../news/list/list'
    })
  },
  index: function () {
    wx.navigateTo({
      url: 'index'
    })
  },
  goods_list: function (e) {
    var category_id = e.currentTarget.dataset.category_id
    wx.navigateTo({
      url: '../goods/list/list?category_id=' + category_id,
    })
  },
  search_list: function () {
    var goods_name = this.data.inputVal;
    wx.navigateTo({
      url: '../goods/list/list?goods_name=' + goods_name,
    })
  },
  goods_info: function (e) {
    var goods_id = e.currentTarget.dataset.goods_id;
    console.log('goods_id->'+goods_id);
    wx.navigateTo({
      url: '../goods/info/info?goods_id=' + goods_id,
    })
  },
  coupon_list(){
    wx.navigateTo({
      url: '../coupon/list/list',
    })
  },
  order_list(){
    wx.navigateTo({
      url: '../order/list/list?status=11',
    })
  },
  brand_info(){
    wx.navigateTo({
      url: '../brand/info',
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
   
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
  
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  }
})